home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / PIECE.CPP < prev    next >
C/C++ Source or Header  |  1994-06-16  |  1KB  |  69 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #include "piece.h"
  4. #include "constant.h"
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. static const unsigned PieceValues[] = 
  9. {
  10.    0,
  11.    64,
  12.    192,
  13.    212,
  14.    320,
  15.    576,
  16.    2000,
  17.    0
  18. };
  19.  
  20. static const char Images[] = "?PNBRQK?";
  21.  
  22. Piece::Piece( PieceType type )
  23. {
  24.    my_piece = type;
  25. }
  26.  
  27. const Piece &Piece::EmptyPiece()
  28. {
  29.    static Piece p(Piece::Empty);
  30.    return p;
  31. }
  32.  
  33. const Boolean Piece::sliding() const
  34. {
  35.    PieceType t = Type();
  36.    return t == Rook || t == Bishop || t == Queen;
  37. }
  38.  
  39. const Piece &Piece::InvalidPiece()
  40. {
  41.    static Piece p(Piece::Invalid);
  42.    return p;
  43. }
  44.  
  45. unsigned Piece::Value() const
  46. {
  47.     return PieceValues[Type()];
  48. }
  49.  
  50. unsigned Piece::Value( PieceType type)
  51. {
  52.     return PieceValues[type];
  53. }
  54.  
  55. Piece::PieceType Piece::Value( const char c )
  56. {
  57.     const char *p = Images;
  58.     p = strchr(p,c);
  59.     if (p)
  60.        return (PieceType)(p-Images);
  61.     else
  62.        return Piece::Invalid;
  63. }
  64.  
  65. char Piece::Image(const Piece::PieceType p)
  66. {
  67.     return Images[p];
  68. }
  69.